package net.zoneland.knowledge.enums;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import net.zoneland.knowledge.constant.FieldConstant;
import net.zoneland.knowledge.model.EsQuestion;

/**
 * .
 *
 * @author: bcc
 *     2022/5/18
 */
public enum LevelEnum {
    LEVEL1(1) {
        @Override
        public void setLevelTitle(Map<String, Object> result, EsQuestion question) {
            result.put(FieldConstant.FIELD_LEVEL1TITLE, question.getLevel1Title());
        }

        @Override
        public boolean removeId(final EsQuestion esQuestion) {
            if (StringUtils.isNotBlank(esQuestion.getLevel2Title())) {
                return true;
            }
            return false;
        }

        @Override
        public void generateSubLevelTitle(final Map<String, Object> result, final EsQuestion question) {
            if (!removeId(question)) {
                result.put(FieldConstant.FIELD_LEVEL2TITLE, question.getQuestion());
            }
        }
    },
    LEVEL2(2) {
        @Override
        public void setLevelTitle(Map<String, Object> result, EsQuestion question) {
            result.put(FieldConstant.FIELD_LEVEL2TITLE, question.getLevel2Title());
        }
        @Override
        public boolean removeId(final EsQuestion esQuestion) {
            if (StringUtils.isNotBlank(esQuestion.getLevel3Title())) {
                return true;
            }
            return false;
        }

        @Override
        public String getTitle(final EsQuestion esQuestion) {

            return esQuestion.getLevel2Title();
        }
        @Override
        public void generateSubLevelTitle(final Map<String, Object> result, final EsQuestion question) {
            if (!removeId(question)) {
                result.put(FieldConstant.FIELD_LEVEL3TITLE, question.getQuestion());
            }
        }
    },
    LEVEL3(3) {
        @Override
        public void setLevelTitle(Map<String, Object> result, EsQuestion question) {
            result.put(FieldConstant.FIELD_LEVEL3TITLE, question.getLevel3Title());
        }

        @Override
        public String getTitle(final EsQuestion esQuestion) {

            return esQuestion.getLevel3Title();
        }
        
        @Override
        public void generateSubLevelTitle(final Map<String, Object> result, final EsQuestion question) {
            if (!removeId(question)) {
                result.put(FieldConstant.FIELD_LEVEL4TITLE, question.getQuestion());
            }
        }
        
    };
    
    private int level;

    LevelEnum(final int level) {

        this.level = level;
    }
    
    public static LevelEnum getByLevel(int level) {
        for(LevelEnum l : LevelEnum.values()) {
            if (level == l.getLevel()) {
                return l;
            }
        }
        return null;
    }
    
    public void setLevelTitle(Map<String, Object> result, EsQuestion esQuestion) {
        
    }
    
    public String getTitle(EsQuestion esQuestion) {
        return esQuestion.getLevel1Title();
    }

    /**
     * 生成下一title.
     * 如三级科目，需要生成level4Title，内容为question
     * @param result
     * @param question
     */
    public void generateSubLevelTitle(Map<String, Object> result, EsQuestion question) {
        
    }
    /**
     * 是否要删除Id
     * @param esQuestion
     * @return
     */
    public boolean removeId(EsQuestion esQuestion) {
        return false;
    }

    /**
     * .
     *
     * @return level
     */
    public int getLevel() {

        return level;
    }

    /**
     * .
     *
     * @param level to set
     */
    public void setLevel(final int level) {

        this.level = level;
    }
}
